﻿@{
    Layout = null;
}
@*流量包*@
<style>
    .form-horizontal .form-group {
        margin-bottom: 15px;
        margin-top: 15px;
    }
    .form-group.money .btn{
        margin-left:5px;
    }
</style>

<form id="LLBPacket" class="form-horizontal" onkeydown="if(event.keyCode==13){return false;}">


    <div class="form-group">
        <div class="col-md-2 text-right">流量包名称：</div>

        <div class="col-md-7">
            <input type="text" name="Name" class="form-control" required>
            <input type="hidden" name="type" value="3" class="form-control" />
        </div>
        <div class="col-md-3"></div>
    </div>
    @*<div class="form-group">
            <div class="col-md-2 text-right">流量类型：</div>
            <div class="col-md-7">
                <select name="CouponType" class="form-control">
                    <option value="1">电信流量</option>
                    <option value="2">移动流量</option>
                    <option value="3">联通流量</option>
                    <option value="4">通用流量</option>
                </select>
            </div>
            <div class="col-md-3"></div>
        </div>*@
    <div class="form-group money">
        <div class="col-md-2 text-right">移动用户：</div>
        <div class="col-md-10" id="mobile">
            <input type="hidden" name="DataID2" value="10" />
        </div>
    </div>


    <div class="form-group money">
        <div class="col-md-2 text-right">电信用户：</div>
        <div class="col-md-10" id="chinaNet">
            <input type="hidden" name="DataID3" value="10" />
        </div>
    </div>


    <div class="form-group money">
        <div class="col-md-2 text-right">联通用户：</div>
        <div class="col-md-10" id="union">
            <input type="hidden" name="DataID1" value="20" />
        </div>
    </div>


    <div class="form-group">
        <div class="col-md-2 text-right">发放数量：</div>
        <div class="col-md-7">
            <input type="number" name="TotalNums" class="form-control">
            <input type="hidden" name="MaxDenomination">
            <input type="hidden" name="MinDenomination">
            <input type="hidden" name="Denomination">
        </div>
        <div class="col-md-3">个</div>
    </div>


    @*<div class="form-group">
                <div class="col-md-2 text-right">发放总流量：</div>
                <div class="col-md-7">
                    <input type="number" name="TotalMoney" class="form-control">
                </div>
                <div class="col-md-3">MB</div>
            </div>
        <div class="form-group">
            <div class="col-md-2 text-right">发放金额：</div>
            <div class="col-md-7">
                <input readonly="readonly" type="text" name="TotalMoney" class="form-control">
            </div>
            <div class="col-md-3">元</div>
        </div>*@
    <div class="form-group">
        <label class="col-md-2 text-right">预计金额：</label>
        <div class="col-md-7">
            <input type="text" readonly="readonly" id="showMoney" class="form-control" />
            <input type="hidden" name="TotalMoney" value=" " />
        </div>
        <div class="col-md-3">元</div>
    </div>
    <div class="form-group">
        <div class="col-md-2 text-right">备注：</div>
        <div class="col-md-7">
            <input id="110" type="text" name="Remark" class="form-control">
        </div>
    </div>

</form>

<script>

      
    $.get('/Market/getFlowTable', '', function (r) {
        var rr = eval('(' + r + ')');
        //console.log(rr.result)
        $(rr.result).each(function (i, ele) {
            if(ele.company==="中国联通")
            {
                $(ele.flows).each(function (i, ele1) {
                    if (i == 0)
                    {
                        $('#union').append('<span class="btn btn-success active-money"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    else {
                        $('#union').append('<span class="btn"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                })
                $('#union').append('<span style="color:#50AE55;padding:4px 12px;">' + ele.flows[0].inprice + '元</span>');
            }
            else if (ele.company === "中国移动")
            {
                $(ele.flows).each(function (i, ele1) {
                    if (i == 0) {
                        $('#mobile').append('<span class="btn btn-success active-money"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    else {
                        $('#mobile').append('<span class="btn"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    
                })
                $('#mobile').append('<span style="color:#50AE55;padding:4px 12px;">' + ele.flows[0].inprice + '元</span>');
            }
            else {
                $(ele.flows).each(function (i, ele1) {
                    if (i == 0) {
                        $('#chinaNet').append('<span class="btn btn-success active-money"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    else {
                        $('#chinaNet').append('<span class="btn"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }

                });
                $('#chinaNet').append('<span style="color:#50AE55;padding:4px 12px;">' + ele.flows[0].inprice + '元</span>');
            }

        })
    })


    $('#LLBPacket div.form-group.money').on('click', 'span.btn', function () {
        $(this).siblings().removeClass('btn-success').addClass('btn-default');
        $(this).removeClass('btn-default').addClass('btn-success');
        $(this).siblings('input[type="hidden"]').val($(this).data("id"));
        $(this).parent().children('span:last').text($(this).data("inprice")+'元');
    });
 
    $('#LLBPacket .col-md-7 input[name="TotalNums"]').bind('keyup blur', function () {
        if ($(this).val() != '') {
            var val = parseInt($(this).val());
            var MinMoney = parseFloat($('#LLBPacket div.form-group.money #chinaNet').children('span:last').text()) * val;
            var MidMoney = parseFloat($('#LLBPacket div.form-group.money #union').children('span:last').text()) * val;
            var TotalMoney = parseFloat($('#LLBPacket div.form-group.money #mobile').children('span:last').text()) * val;
            $('#LLBPacket .col-md-7 #showMoney').val(Math.min(MinMoney, MidMoney, TotalMoney).toFixed(3) + ' ~ ' + Math.max(MinMoney, MidMoney, TotalMoney).toFixed(3)).next().val(Math.max(MinMoney, MidMoney, TotalMoney).toFixed(3));
            $('#LLBPacket .col-md-7 input[type="hidden"][name="MaxDenomination"]').val((Math.max(MinMoney, MidMoney, TotalMoney) / val).toFixed(3)).next().val((Math.min(MinMoney, MidMoney, TotalMoney) / val).toFixed(3)).next().val((Math.max(MinMoney, MidMoney, TotalMoney) / val).toFixed(3));
        }
    })





    $('#LLBPacket').bootstrapValidator({
   
        fields: {
            Template: {
                validators: {
                    notEmpty: {
                        message: '模板名称不能为空'
                    },
                }
            },
            Name: {
                validators: {
                    notEmpty: {
                        message: '流量包名称不能为空'
                    },
                }
            },
            TotalNums: {
                validators: {
                    notEmpty: {
                        message: '发放数量不能为空'
                    },
                    regexp: {
                        regexp: /^[1-9]\d*$/,
                        message: '请输入大于0的整数'
                    }
                }
            },
        }
    });
   
   
</script>
